<%@ include file="/common/taglibs.jsp" %>

<head>
    <title><fmt:message key="login.title"/></title>
    <meta name="menu" content="Login"/>
</head>
<body>
<!-- Main content -->
<section class="content">
    <div class="login-box">
        <div class="login-logo">
            <b><fmt:message key="login.heading"/></b>
        </div>
        <!-- /.login-logo -->
        <div class="login-box-body">
            <form method="post" id="loginForm" action="<c:url value='/j_security_check'/>"
                  onsubmit="saveUsername(this);return validateForm(this)" class="form-signin" autocomplete="off">

                <c:if test="${param.error != null}">
                    <div class="alert alert-danger alert-dismissable">
                        <fmt:message key="errors.password.mismatch"/>
                    </div>
                </c:if>
                <div class="form-group has-feedback">
                    <input type="text" name="j_username" id="j_username" class="form-control"
                           placeholder="<fmt:message key="label.username"/>" required tabindex="1">
                </div>
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" name="j_password" id="j_password" tabindex="2"
                           placeholder="<fmt:message key="label.password"/>" required>
                </div>


                <div class="row">
                    <div class="col-xs-8">
                        <div class="checkbox icheck">
                            <label>
                                <c:if test="${appConfig['rememberMeEnabled']}">
                                    <input type="checkbox" name="_spring_security_remember_me" />
                                    <fmt:message key="login.rememberMe"/>
                                </c:if>
                            </label>
                        </div>
                    </div>
                    <!-- /.col -->
                    <div class="col-xs-4">
                        <button type="submit" class="btn btn-primary btn-block btn-flat" name="login" tabindex="4">
                            <fmt:message key='button.login'/>
                        </button>
                    </div>
                    <!-- /.col -->
                </div>

            </form>



            <p><fmt:message key="login.passwordHint"/></p>

            <p><fmt:message key="updatePassword.requestRecoveryTokenLink"/></p>
        </div>
    </div>
</section>
<!-- /.content -->

<c:set var="scripts" scope="request">
    <script type="text/javascript">
        if ($.cookie("username") != null && $.cookie("username") != "") {
            $("#j_username").val($.cookie("username"));
            $("#j_password").focus();
        } else {
            $("#j_username").focus();
        }

        function saveUsername(theForm) {
            $.cookie("username",theForm.j_username.value, { expires: 30, path: "<c:url value="/"/>"});
        }

        function validateForm(form) {
            var valid = validateRequired(form);
            if (valid == false) {
                $(".form-group").addClass('error');
            }
            return valid;
        }

        function passwordHint() {
            if ($("#j_username").val().length == 0) {
                alert("<fmt:message key="errors.required"><fmt:param><fmt:message key="label.username"/></fmt:param></fmt:message>");
                $("#j_username").focus();
            } else {
                location.href="<c:url value="/passwordHint"/>?username=" + $("#j_username").val();
            }
        }

        function requestRecoveryToken() {
            if ($("#j_username").val().length == 0) {
                alert("<fmt:message key="errors.required"><fmt:param><fmt:message key="label.username"/></fmt:param></fmt:message>");
                $("#j_username").focus();
            } else {
                location.href="<c:url value="/requestRecoveryToken"/>?username=" + $("#j_username").val();
            }
        }

        function required () {
            this.aa = new Array("j_username", "<fmt:message key="errors.required"><fmt:param><fmt:message key="label.username"/></fmt:param></fmt:message>", new Function ("varName", " return this[varName];"));
            this.ab = new Array("j_password", "<fmt:message key="errors.required"><fmt:param><fmt:message key="label.password"/></fmt:param></fmt:message>", new Function ("varName", " return this[varName];"));
        }
    </script>

</c:set>
</body>